<?php

/**
 * This is the model class for table "{{cmp_contact}}".
 *
 * The followings are the available columns in table '{{cmp_contact}}':
 * @property integer $zcc_id
 * @property integer $zm_id
 * @property string $zcc_name
 * @property integer $zcc_sex
 * @property string $zcc_job
 * @property string $zcc_tel
 * @property string $zcc_email
 * @property string $zcc_fax
 * @property string $zcc_mob
 * @property integer $zcc_zip
 * @property integer $zar_id
 * @property string $zcc_address
 * @property integer $zcc_listorder
 * @property integer $zcc_default
 */
class CmpContact extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return CmpContact the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{cmp_contact}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('zm_id, zcc_sex, zcc_zip, zar_id, zcc_listorder, zcc_default', 'numerical', 'integerOnly'=>true),
			array('zcc_name, zcc_job, zcc_tel, zcc_fax', 'length', 'max'=>20),
			array('zcc_email, zcc_address', 'length', 'max'=>255),
			array('zcc_mob', 'length', 'max'=>11),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('zcc_id, zm_id, zcc_name, zcc_sex, zcc_job, zcc_tel, zcc_email, zcc_fax, zcc_mob, zcc_zip, zar_id, zcc_address, zcc_listorder, zcc_default', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'zcc_id' => 'Zcc',
			'zm_id' => 'Zm',
			'zcc_name' => 'Zcc Name',
			'zcc_sex' => 'Zcc Sex',
			'zcc_job' => 'Zcc Job',
			'zcc_tel' => 'Zcc Tel',
			'zcc_email' => 'Zcc Email',
			'zcc_fax' => 'Zcc Fax',
			'zcc_mob' => 'Zcc Mob',
			'zcc_zip' => 'Zcc Zip',
			'zar_id' => 'Zar',
			'zcc_address' => 'Zcc Address',
			'zcc_listorder' => 'Zcc Listorder',
			'zcc_default' => 'Zcc Default',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('zcc_id',$this->zcc_id);
		$criteria->compare('zm_id',$this->zm_id);
		$criteria->compare('zcc_name',$this->zcc_name,true);
		$criteria->compare('zcc_sex',$this->zcc_sex);
		$criteria->compare('zcc_job',$this->zcc_job,true);
		$criteria->compare('zcc_tel',$this->zcc_tel,true);
		$criteria->compare('zcc_email',$this->zcc_email,true);
		$criteria->compare('zcc_fax',$this->zcc_fax,true);
		$criteria->compare('zcc_mob',$this->zcc_mob,true);
		$criteria->compare('zcc_zip',$this->zcc_zip);
		$criteria->compare('zar_id',$this->zar_id);
		$criteria->compare('zcc_address',$this->zcc_address,true);
		$criteria->compare('zcc_listorder',$this->zcc_listorder);
		$criteria->compare('zcc_default',$this->zcc_default);

		$criteria->order = " zcc_listorder DESC ";//默认为时间倒序
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}